package sample.testAbcPic 
{
	
	import com.bit101.components.PushButton;
	import com.bit101.components.Text;
	
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.utils.getTimer;
	
	import org.abc.uiCore.AbcPic;
	import org.abc.uiCore.vo.PicVo;
	
	/**
	 * @describe  	测试AbcPic
	 * @author  	Mr.zheng
	 * @website 	http://blog.sina.com.cn/zihua2007
	 * @time		2011-9-9 18:39
	 */
	public class TestAbcPic extends Sprite
	{
		private var _picVo:PicVo;
		private var _pic:AbcPic;
		
		private var createBtn:PushButton;
		private var createOneBtn:PushButton;
		private var timeTxt:Text;
		
		private var gapTime:int;
		
		public function TestAbcPic() 
		{
			createBtn = new PushButton(this, 0, 300, "创建pic", onCreateBtn);
			createOneBtn = new PushButton(this, 0, 320, "创建one pic", onOneCreateBtn);
			timeTxt = new Text(this);
		}
		
		/* public function */
		
		/* override function */
		
		/* private function */
		private function onCreateBtn(e:Event):void 
		{
			gapTime = getTimer();
			for (var i:int = 0; i < 10; i++) 
			{
				createPic();
			}
			gapTime = getTimer() - gapTime;
			timeTxt.text="间隔时间：" + gapTime;
		}
		
		private function onPicClick(e:MouseEvent):void 
		{
			var pic:AbcPic = e.currentTarget as AbcPic;
			pic.removeEventListener(MouseEvent.CLICK, onPicClick);
			pic.dispose();
		}
		
		private function onOneCreateBtn(e:MouseEvent):void 
		{
			createPic();
			createPic();
		}
		private function createPic():void {
			_picVo = new PicVo("../asset/pic.jpg",0);	//创建vo
			_pic = new AbcPic(_picVo);						//创建pic
			_pic.bindView(new pic_CPS());					//和素材绑定
			_pic.init();									//初始化
			_pic.update();									//显示图片
			_pic.addEventListener(MouseEvent.CLICK, onPicClick);
			addChild(_pic);
			
			_pic.x  = Math.random() * 500;
			_pic.y  = Math.random() * 380;
		}
	}
	
}